package com.example.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.bean.MovieInfo;
import com.example.bean.SpecialZone;
import com.example.doubanfilm.R;

import java.util.ArrayList;
import java.util.List;

public class RecyclerViewAdapterForMainitem extends BaseQuickAdapter<MovieInfo, BaseViewHolder> {

    private List<MovieInfo> data;
    private Context context;

    public RecyclerViewAdapterForMainitem(int layoutResId, @Nullable List<MovieInfo> data,Context context) {
        super(layoutResId, data);
        this.data = data;
        this.context = context;
    }

    public void setData(List<MovieInfo> data) {
        this.data = data;
    }

    @Override
    protected void convert(BaseViewHolder helper, MovieInfo item) {

        ImageView iv = helper.getView(R.id.mainItem_iv);
        Glide.with(context).load(item.getCover()).into(iv);
        helper.setText(R.id.mainItem_tv,item.getName());

        GridView gridView = helper.getView(R.id.main_GridView);
        gridView.setAdapter(new MainGridViewAdapter(getList(item.getScore())));
        helper.setText(R.id.main_score,item.getScore());

    }
    public static List<Integer> getList(String scoreStr){

        List<Integer> list = new ArrayList<>(5);
        double score = Double.parseDouble(scoreStr);

        double args = score / 10 * 5;

        double intScore = Math.floor(args);

        if (args > Math.floor(args)){
            for (int i = 0; i < intScore; i++) {
                list.add(R.mipmap.rate_light);
            }
            list.add(R.mipmap.rate_half);
            final int gray = 5 - list.size();
            if (list.size() < 5){
                for (int j = 0; j < gray; j++) {
                    list.add(R.mipmap.rate_gray);
                }
            }

            return list;
        }else {
            for (int i = 0; i < intScore; i++) {
                list.add(R.mipmap.rate_light);
            }
            if (list.size() <= 5) {
                for (int i = 0; i < 5 - list.size(); i++) {
                    list.add(R.mipmap.rate_gray);
                }
            }
            return list;
        }
    }
}



